package view;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;
import model.db.table.BidHistory;

/**
 * Author: Raoux Etienne
 * Student login: jc218934
 * Student number: 12448190
 * email: etienne.raoux@my.jcu.edu.au
 * alt email: jc218934@gmail.com
 */
public class ItemDisplayPanel extends JPanel
{
    private BidHistory bidHistory;
    public ItemDisplayPanel(BidHistory bidHistory)
    {
        this.bidHistory = bidHistory;
        JPanel itemDescPanel = new JPanel();
        ImagePanel itemImgPanel;
        JLabel itemSellerLabel = new JLabel();
        JLabel priceLabel = new JLabel();
        JLabel sellerUrlLabel = new JLabel();
        JLabel itemDescriptionUrlLabel = new JLabel();

        setLayout(new java.awt.BorderLayout());

        itemImgPanel = new ImagePanel("web/"+bidHistory.getImgUrl());
        add(itemImgPanel, java.awt.BorderLayout.WEST);

        itemDescPanel.setLayout(new javax.swing.BoxLayout(itemDescPanel, javax.swing.BoxLayout.Y_AXIS));

        priceLabel.setText("price = "+bidHistory.getPrice());
        itemDescPanel.add(priceLabel);

        itemSellerLabel.setText("seller = "+bidHistory.getSellerName());
        itemDescPanel.add(itemSellerLabel);

        sellerUrlLabel.setText("sellerUrl = "+bidHistory.getSellerUrl());
        itemDescPanel.add(sellerUrlLabel);

        itemDescriptionUrlLabel.setText("description url = "+bidHistory.getItemUrl());
        itemDescPanel.add(itemDescriptionUrlLabel);

        add(itemDescPanel, java.awt.BorderLayout.CENTER);

        setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 3), bidHistory.getTitle()));
        addMouseListener(new ItemPressed());
    }

    private class ItemPressed implements MouseListener
    {
        public void mouseClicked(MouseEvent e)
        {
            ((ItemView) e.getComponent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent().getParent()).changeViewToItemBidHistoryView(bidHistory);
        }

        public void mousePressed(MouseEvent e)
        {
        }

        public void mouseReleased(MouseEvent e)
        {
        }

        public void mouseEntered(MouseEvent e)
        {
        }

        public void mouseExited(MouseEvent e)
        {
        }
    }
}
